<?php

	// TITLE: Phone_type AUTO MODEL
	// FILE: scaffolding/model/phone_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createPhoneType = function($con, $phoneType) {
		$sql = 'INSERT INTO phone_type (id, title, code, description) VALUES (';
		$sql .= $phone_type->getId() . ', ';
		$sql .= $phone_type->getTitle() . ', ';
		$sql .= $phone_type->getCode() . ', ';
		$sql .= $phone_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readPhoneType = function($con, $id) {
		$sql = 'SELECT * FROM phone_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$phoneType = new PhoneType();
			$phoneType->setId(result[0]);
			$phoneType->setTitle(result[1]);
			$phoneType->setCode(result[2]);
			$phoneType->setDescription(result[3]);
		} else {
			$phoneType = false;
		}
		return $phoneType;
	};

	$updatePhoneType = function($con, $phoneType) {
		$sql = 'UPDATE phone_type SET ';
		$sql .= 'id = ' . $phone_type->getId() . ', ';
		$sql .= 'title = ' . $phone_type->getTitle() . ', ';
		$sql .= 'code = ' . $phone_type->getCode() . ', ';
		$sql .= 'description = ' . $phone_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deletePhoneType = function($con, $id) {
		$sql = 'DELETE FROM phone_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listPhoneType = function($con) {
		$sql = 'SELECT * FROM phone_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$phoneTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$phoneType = new PhoneType();
				$phoneType->setId(result[0]);
				$phoneType->setTitle(result[1]);
				$phoneType->setCode(result[2]);
				$phoneType->setDescription(result[3]);
				$phoneTypes[] = phoneType;
			}// end while
		} else {
			$phoneTypes = false;
		}
		return $phoneTypes;
	};

